package com.guowen.myaccount.frag_record;


import com.guowen.myaccount.R;
import com.guowen.myaccount.db.DBManager;
import com.guowen.myaccount.db.TypeBean;

import java.util.List;


public class OutcomeFragment extends BaseRecordFragment {

    // 重写
    @Override
    public void loadDataGrid() {
        super.loadDataGrid();
        // 获取数据库当中的数据源
        List<TypeBean> outList = DBManager.getTypeList(0);
        typeList.addAll(outList);
        adapter.notifyDataSetChanged();
        typeText.setText("其他");
        typeImage.setImageResource(R.mipmap.ic_qita_fs);

        if (type == 1){
            String name1 = accountBean.getTypename();
            for(int i = 0; i < outList.size(); i++){
                String name2 = outList.get(i).getTypename();
                if (name1.equals(name2)){
                    TypeBean typeBean = outList.get(i);
                    adapter.selectPos = typeBean.getId()-1;
                    adapter.notifyDataSetChanged();
                }
            }
        }

    }

    @Override
    public void saveAccountToDB() {
        type = 0;
        accountBean.setKind(0);
        Float money = Float.parseFloat(moneyEdit.getText().toString());
        accManageBean.setMoney(accManageBean.getMoney()-money);
        DBManager.insertItemToAccounttb(accountBean);
    }

    @Override
    public void alterAccountToDB() {
        type = 1;
        accountBean.setKind(0);
        Float money = Float.parseFloat(moneyEdit.getText().toString());
        accManageBean.setMoney(accManageBean.getMoney()+old_money-money);
        DBManager.alterItemFromAccounttbById(id, accountBean);
    }


}